<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('选择班级')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <input type="hidden" id="classIds" th:value="${classIds}"/>
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>课程名称：</label>
                                <input type="text" name="courseName" placeholder="请输入课程名称"/>
                            </li>
                            <li>
                                <label>任课老师：</label>
                                <input type="text" name="teaName" placeholder="请输入老师姓名"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var superAdminFlag = [[${@permission.hasPermi('system:superAdmin:opt')}]];
        var prefix = ctx + "system/common";

        $(function() {
            var options = {
                url: prefix + "/searchClass",
                modalName: "选择班级",
                sortName: "id",
                sortOrder: "desc",
                columns: [{
                    checkbox: true,
                    formatter:function (value, row, index) {
                        var ids = $("#classIds").val();
                        if (ids) {
                            var arr = ids.split(',');
                            for (var i = 0; i < arr.length; i++) {
                                if (arr[i] == row.id) {
                                    return { checked: true };
                                }
                            }
                        }
                        return { checked: false };
                    }
                },
                {
                    visible: false,
                    field: 'id',
                    title: '编号'
                },
                {
                    field: 'course.name',
                    title: '课程名称'
                },
                {
                    field: 'name',
                    title: '班级名称'
                },
                {
                    field: 'beginDate',
                    title: '上课日期'
                },
                {
                    field: 'course.standardCoursePrice',
                    title: '单价'
                },
                {
                    field: 'courseNum',
                    title: '课次'
                },
                {
                    title: '授课方式',
                    formatter: function (value, row, index) {
                        return classTypeTools (row);
                    }
                },
                {
                    field: 'teacher.userName',
                    title: '任课老师'
                }
                ]
            };
            $.table.init(options);
        });

        function classTypeTools(row) {
            if (row.course.classType == 0) {
                return '线下';
            }
            return '线上';
        }

        function submitHandler() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var ids = rows.join();
            parent.chooseClass(ids);
            $.modal.close();
        }

        function classTypeTools(row) {
            if (row.classType == 0) {
                return '线下';
            }
            return '线上';
        }

    </script>
</body>
</html>